// app/model/plugin_data_batch_model.js
'use strict';

module.exports = app => {
  const { INTEGER, STRING, TEXT, DATE, BIGINT } = app.Sequelize;
  
  const PluginDataBatch = app.model.define('plugin_data_batch', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    batchId: {
      type: STRING(100),
      allowNull: false,
      unique: true,
      field: 'batch_id',
      comment: '批次ID'
    },
    dataType: {
      type: STRING(50),
      allowNull: true,
      field: 'data_type',
      comment: '数据类型（bank/order/invoice）'
    },
    count: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      field: 'count',
      comment: '数据条数'
    },
    status: {
      type: STRING(20),
      allowNull: false,
      defaultValue: 'pending',
      field: 'status',
      comment: '处理状态（pending/processing/completed/failed）'
    },
    processedCount: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      field: 'processed_count',
      comment: '已处理条数'
    },
    failedCount: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      field: 'failed_count',
      comment: '失败条数'
    },
    processingTime: {
      type: INTEGER,
      allowNull: true,
      field: 'processing_time',
      comment: '处理耗时（毫秒）'
    },
    createdAt: {
      type: DATE,
      allowNull: false,
      field: 'created_at',
      comment: '创建时间'
    },
    updatedAt: {
      type: DATE,
      allowNull: false,
      field: 'updated_at',
      comment: '更新时间'
    },
    completedAt: {
      type: DATE,
      allowNull: true,
      field: 'completed_at',
      comment: '完成时间'
    },
    errorMessage: {
      type: TEXT,
      allowNull: true,
      field: 'error_message',
      comment: '错误信息'
    }
  }, {
    tableName: 'plugin_data_batches',
    comment: '插件数据批次表',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  });
  
  return PluginDataBatch;
};